﻿package kizzo.utils 
{
	import flash.events.Event;
	import flash.events.EventDispatcher;

	public class MultiTweener extends EventDispatcher
	{
		private var tweens_array:Array;
		private var tweens_running:uint;		
		
		public function MultiTweener() 
		{
			this.tweens_array = [];
		}
				
		public function add(tween:BaseTweener):void
		{
			this.tweens_array.push(tween);
			
		}		

		public function reset():void 
		{
			this.tweens_array = [];
		}
				
		public function step_to_start():void
		{
			this.tweens_running = 0;
			
			for (var i:uint = 0; i < this.tweens_array.length; i++)
			{	
				this.tweens_array[i].step_to_start();
				this.tweens_array[i].addEventListener(BaseTweener.TWEEN_START, tween_end_hnd);
				this.tweens_running ++;
			}			
		}
				
		private function tween_end_hnd(evt:Event):void
		{					
			if (!--this.tweens_running)			
			{																
				dispatchEvent(new Event(BaseTweener.TWEEN_END));
			}
		}
				
		public function step_to_end():void
		{
			this.tweens_running = 0;
			
			for (var i:uint = 0; i < this.tweens_array.length; i++)
			{				
				this.tweens_array[i].step_to_end();
				this.tweens_array[i].addEventListener(BaseTweener.TWEEN_END, tween_end_hnd);
				this.tweens_running ++;
			}			
		}
				
		private function update():void
		{			
			
		}	
		
		
	}
	
}